package com.cc.pureCoffee.controller;

import com.cc.pureCoffee.common.R;
import com.cc.pureCoffee.entity.Employee;
import com.cc.pureCoffee.entity.User;
import com.cc.pureCoffee.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;


@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 发送手机验证码
     *
     * @param user
     * @return
     */
    @PostMapping ("/sendMsg")
    public R<String> sendMsg(@RequestBody User user, HttpSession session) {
        userService.sendMsg(user, session);
        return R.success("手机验证码发送成功！");
    }
//    public R<String> sendMsg(@RequestBody User user, HttpSession session)
//    {
//        userService.sendMsg(user, session);
//        return R.success("手机验证码发送成功！");
//    }


    /**
     * 用户登录
     *
     * @param map
     * @param session
     * @return
     */
    @PostMapping("/login")
    public R<User> login(@RequestBody Map map, HttpSession session) {
        return userService.login(map, session);
    }

    /**
     * 退出登录
     *
     * @param request
     * @return
     */
    @PostMapping("/loginout")
    public R<String> logout(HttpServletRequest request) {
        return userService.logout(request);
    }
}
